<template>
  <div>
    <el-dialog
      title="人工调整"
      :visible.sync="showDialog"
      width="566px"
      @close="btnCancel"
    >
      <el-form
        ref="firstForm"
        label-width="120px"
        style="width: 100%"
      >
        <el-form-item class="work-type">
          <el-radio
            v-model="workPattern.workPatternType"
            label="1"
          >礼拜制</el-radio>
          <el-radio
            v-model="workPattern.workPatternType"
            label="2"
          >连续制</el-radio>
        </el-form-item>
        <el-form-item label="模式名称:">
          <el-select
            v-model="workPattern.workPatternId"
            clearable
            placeholder="请选择"
            filterable
            class="history-name"
          >
            <el-option
              v-for="item in workPatternObj[workPattern.workPatternType]"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
        style="text-align: center"
      >
        <el-button
          type="warning"
          class="save-btn"
          @click="btnOK"
        >确认</el-button>
        <el-button
          class="cancel-btn is-plain"
          @click="btnCancel"
        >取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { peopleSet } from '@/api/transit'
export default {
  props: {
    workPatternObj: {
      type: Object,
      default: null
    },
    userIdList: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      showDialog: false,
      workPattern: {
        workPatternType: '1',
        workPatternId: ''
      }
    }
  },
  methods: {
    openDialog() {
      this.showDialog = true
    },
    btnCancel() {
      this.showDialog = false
    },
    async btnOK() {
      const res = await peopleSet({ userIdList: this.userIdList, ...this.workPattern })
      if (res.code === 200) {
        this.$message.success(`绑定排班成功`)
        this.$emit('updateWorkPatternList')
      } else {
        this.$message.error(res.msg)
      }
      this.btnCancel()
    },
    async getWorkPatternDetail() {}
  }
}
</script>
<style lang="scss" scoped>
.work-type {
  ::v-deep .el-form-item__content {
    margin-left: 40px !important;
  }
  ::v-deep .el-radio:first-child {
    margin-right: 80px !important;
  }
  ::v-deep .el-radio__label {
    font-weight: bold;
    color: #333333;
  }
}
::v-deep .el-form {
  .el-form-item {
    label {
      font-weight: 700;
    }
  }
}
.history-name {
  width: auto !important;
  ::v-deep .el-input__inner {
    width: 293px;
  }
}
</style>

